<html>
<head>
<style>
.failed {
    color: red;
    font-weight: bold;
}

.passed {
    color: green;
    font-weight: bold;
}
</style>
<script src=../../resources/testharness.js></script>
<script src=../../resources/testharnessreport.js></script>
</head>
<body>
<h1 id="heading"/>
<script>
var count = 0;

function shouldThrowException(node)
{
    var xs = new XMLSerializer();
    assert_throws_js(TypeError, () => { xs.serializeToString.apply(xs, arguments); }, ++count + ". Verifying XMLSerializer.serializeToString() should THROW exception with " + (arguments.length ? "argument " + node : "no argument"));
}

function shouldNOTThrowException(node)
{
    var xs = new XMLSerializer();
    ++count;
    try {
        var str = xs.serializeToString(node);
    } catch (exception) {
        assert_unreached(count + ". Verifying XMLSerializer.serializeToString() should NOT-THROW exception with argument " + node);
    }
}

test(() => {
    shouldThrowException();
    shouldThrowException(null);
    shouldThrowException(undefined);
    shouldThrowException("<html><title>Hello World</title></html>");
    shouldThrowException(document.children);

    shouldNOTThrowException(document);
    shouldNOTThrowException(document.documentElement);
    shouldNOTThrowException(document.firstChild);
    shouldNOTThrowException(document.createElement("div"));
    shouldNOTThrowException(document.getElementById("heading"));
    shouldNOTThrowException(document.createElement("custom"));

    var domParser = new DOMParser();

    var htmlDoc = domParser.parseFromString("<html/>", "text/html");
    shouldNOTThrowException(htmlDoc);
    shouldNOTThrowException(htmlDoc.firstChild);

    var xmlDoc = domParser.parseFromString("<root/>", "text/xml");
    shouldNOTThrowException(xmlDoc);
    shouldNOTThrowException(xmlDoc.lastChild);
}, "This tests XMLSerializer.serializeToString() throwing exception when node value is invalid and passing otherwise");
</script>
</body>
</html>
